﻿// The MIT License (MIT)
// Copyright (c) 2013 Stylianos Dritsas
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.

using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using System.Diagnostics;

using Rhino;
using Rhino.PlugIns;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Input;

#region -- Metadata -----------------------------------------------------------

[assembly: AssemblyTitle(                                   "RhSgPlugIn"                            )]
[assembly: AssemblyDescription(                             "Rhino Smart Geometry Workshop"         )]
[assembly: AssemblyConfiguration(                           "R5R0"                                  )]
[assembly: AssemblyCompany(                                 "Sutd"                                  )]
[assembly: AssemblyProduct(                                 "RhSgPlugIn"                            )]
[assembly: AssemblyCopyright(                               "Copyright © 2013 by Stylianos Dritsas" )]
[assembly: AssemblyTrademark(                               ""                                      )]
[assembly: AssemblyCulture(                                 ""                                      )]
[assembly: ComVisible(                                      false                                   )]
[assembly: Guid(                                            "2582d111-2c64-4936-bc77-0dc6b61694ff"  )]
[assembly: AssemblyVersion(                                 "1.0.0.0"                               )]
[assembly: AssemblyFileVersion(                             "1.0.0.0"                               )] 

[assembly: PlugInDescription( DescriptionType.Address,      "20 Dover Drive"                        )]
[assembly: PlugInDescription( DescriptionType.Country,      "Singapore"                             )]
[assembly: PlugInDescription( DescriptionType.Email,        "dritsas@sutd.edu.sg"                   )]
[assembly: PlugInDescription( DescriptionType.Phone,        "+65 81639730"                          )]
[assembly: PlugInDescription( DescriptionType.Fax,          "N/A"                                   )]
[assembly: PlugInDescription( DescriptionType.Organization, "Sutd"                                  )]
[assembly: PlugInDescription( DescriptionType.UpdateUrl,    "http://sutd.edu.sg"                    )]
[assembly: PlugInDescription( DescriptionType.WebSite,      "http://sutd.edu.sg"                    )]

#endregion

namespace Sutd
{
  #region -- Command ----------------------------------------------------------

  //-- Command Class
  //--
  [Guid( "38689cbb-e490-4f92-bb1b-4c7f2fc4fbfb" )]
  public partial class Command : Rhino.Commands.Command
  {
    //-- Last Method Invoked
    //--
    private string command;

    public override string EnglishName
    {
      get 
      {
        return PlugIn.Name; 
      }
    }

    //-- Invokes Internal Methods by Name
    //-- Using Reflection
    //
    protected override Result RunCommand( RhinoDoc doc, RunMode mode )
    {
      var result = RhinoGet.GetString( "Command", false, ref command );
      if( result == Result.Success )
      {
        try
        {
          var type = typeof( Command );
          type.InvokeMember( command, BindingFlags.InvokeMethod, null, this, new object[0] );
        }
        catch         
        {
          Rhino.RhinoApp.WriteLine( "Command {0} failed", command );
        }
      }
      return Result.Success;
    }

    //-- Print Text Message
    //--
    public static void Plot( string text )
    {
      Rhino.RhinoApp.WriteLine( text );
    }
  }
  
  #endregion

  #region -- Plugin -----------------------------------------------------------

  //-- Plugin Class
  //--
  public class PlugIn : Rhino.PlugIns.PlugIn
  {
    public const string NAME = "RhSg";

    public PlugIn( ) : base( )
    {

    }

    protected override LoadReturnCode OnLoad( ref string message )
    {
      return LoadReturnCode.Success;
    }
  }

  #endregion

}
